'''
Created on May 12, 2010

@author: roni
'''
def all_subsets_of_size(k,items):
    ''' Returns all the subsets of items of size k '''
    all_subsets = []
    items_to_choose = list(items)
    __add_all_subsets_of_size(k, items_to_choose,[],0,all_subsets)
    return all_subsets


def __add_all_subsets_of_size(k, items_to_choose, selected_items,next_index,all_subsets):
    ''' Internal function for the recursion '''
    if k==0:
        all_subsets.append(set(selected_items))
        return
        
    for i in xrange(next_index, len(items_to_choose)-(k-1)):
        selected_items.append(items_to_choose[i])
        __add_all_subsets_of_size(k-1,items_to_choose,selected_items,i+1,all_subsets)
        selected_items.remove(items_to_choose[i])               